package net.csdn.business.common.domain.request.issue;

import lombok.*;
import net.csdn.business.common.enums.ResultCodeEnum;
import net.csdn.business.common.exception.BusinessException;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.io.Serializable;
import java.util.List;

/**
 * @author wanghang
 * @version 1.0
 * @date 2022/11/11 15:37
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IssueBatchHandleDto implements Serializable {


    /** 组织ID/仓库ID */
    @NotBlank(message = "sourceId不能为空")
    private String sourceId;
    /** 1:组织；2:仓库 */
    @NotNull(message = "sourceType不能为空")
    @Range(min = 1, max = 2, message = "sourceType不合法")
    private Integer sourceType;

    /**
     * 操作类型
     */
    @NotNull(message = "flag 不能为空")
    private Integer flag;


    /**
     * 批量issueId
     */
    @NotNull(message = "issueIds 不能为空")
    private List<String> issueIds;

    /**
     * 批量处理参数
     */
    @NotNull(message = "handleParam 不能为空")
    private Object handleParam;


    @Getter
    @AllArgsConstructor
    public static enum HandleType {
        CHANGE_STATUS(1, "变更状态"),
        ASSIGN_LEADER(2, "设置负责人"),
        SET_LABEL(3, "设置Label"),
        SET_MILEPOST(4, "设置里程碑");

        private Integer code;
        private String desc;

        public static HandleType ofCode(Integer code) {
            for (HandleType type : HandleType.values()) {
                if (type.code.equals(code)) {
                    return type;
                }
            }
            throw new BusinessException(ResultCodeEnum.PARAMETER_ERROR_CUSTOM, "flag");
        }
    }

}
